#include "autoassignprogrambinding.h"

AutoAssignProgramBinding::AutoAssignProgramBinding()
{
}


QString AutoAssignProgramBinding::GetBinding(const QString &programParameter)
{
  if (programParameter.contains("texture", Qt::CaseInsensitive))
    {
      if (programParameter.contains("0", Qt::CaseInsensitive)) return "TEXTURE0";
      if (programParameter.contains("1", Qt::CaseInsensitive)) return "TEXTURE1";
      if (programParameter.contains("2", Qt::CaseInsensitive)) return "TEXTURE2";
      if (programParameter.contains("3", Qt::CaseInsensitive)) return "TEXTURE3";
      if (programParameter.contains("4", Qt::CaseInsensitive)) return "TEXTURE4";
      if (programParameter.contains("5", Qt::CaseInsensitive)) return "TEXTURE5";
      if (programParameter.contains("6", Qt::CaseInsensitive)) return "TEXTURE6";
      if (programParameter.contains("7", Qt::CaseInsensitive)) return "TEXTURE7";
      if (programParameter.contains("diffuse", Qt::CaseInsensitive)) return "TEXTURE0";
      if (programParameter.contains("normal", Qt::CaseInsensitive)) return "TEXTURE1";
      if (programParameter.contains("heightmap", Qt::CaseInsensitive)) return "TEXTURE1";
      if (programParameter.contains("specular", Qt::CaseInsensitive)) return "TEXTURE2";
      return "TEXTURE0";
    }
  if (programParameter.contains("matrix", Qt::CaseInsensitive))
    {
      if (programParameter.contains("world", Qt::CaseInsensitive)) return "MATRIX_WORLD";
      if (programParameter.contains("view", Qt::CaseInsensitive)) return "MATRIX_VIEW";
      if (programParameter.contains("projection", Qt::CaseInsensitive)) return "MATRIX_PROJECTION";
      return "MATRIX";
    }
  if (programParameter.contains("light", Qt::CaseInsensitive))
    {
      if (programParameter.contains("ambient", Qt::CaseInsensitive)) return "LIGHT_AMBIENT";
      if (programParameter.contains("diffuse", Qt::CaseInsensitive)) return "LIGHT_DIFFUSE";
      if (programParameter.contains("specular", Qt::CaseInsensitive)) return "LIGHT_SPECULAR";
      if (programParameter.contains("position", Qt::CaseInsensitive)) return "LIGHT_POSITION";
      if (programParameter.contains("range", Qt::CaseInsensitive)) return "LIGHT_RANGE";
      return "LIGHT";
    }
  if (programParameter.contains("material", Qt::CaseInsensitive))
    {
      if (programParameter.contains("ambient", Qt::CaseInsensitive)) return "MATERIAL_AMBIENT";
      if (programParameter.contains("diffuse", Qt::CaseInsensitive)) return "MATERIAL_DIFFUSE";
      if (programParameter.contains("specular", Qt::CaseInsensitive)) return "MATERIAL_SPECULAR";
      if (programParameter.contains("shininess", Qt::CaseInsensitive)) return "MATERIAL_SHININESS";
      if (programParameter.contains("emission", Qt::CaseInsensitive)) return "MATERIAL_EMISSION";
      return "MATERIAL";
    }
  if (programParameter.contains("vertex", Qt::CaseInsensitive))
    {
      if (programParameter.contains("0", Qt::CaseInsensitive)) return "POSITION0";
      if (programParameter.contains("1", Qt::CaseInsensitive)) return "POSITION1";
      return "POSITION0";
    }
  if (programParameter.contains("position", Qt::CaseInsensitive))
    {
      if (programParameter.contains("0", Qt::CaseInsensitive)) return "POSITION0";
      if (programParameter.contains("1", Qt::CaseInsensitive)) return "POSITION1";
      return "POSITION0";
    }
  if (programParameter.contains("normal", Qt::CaseInsensitive))
    {
      if (programParameter.contains("0", Qt::CaseInsensitive)) return "NORMAL0";
      if (programParameter.contains("1", Qt::CaseInsensitive)) return "NORMAL1";
      return "NORMAL0";
    }
  if (    programParameter.contains("tex", Qt::CaseInsensitive)
      ||  programParameter.contains("txt", Qt::CaseInsensitive))
    {
      if (programParameter.contains("0", Qt::CaseInsensitive)) return "TEXCOORD0";
      if (programParameter.contains("1", Qt::CaseInsensitive)) return "TEXCOORD1";
      if (programParameter.contains("2", Qt::CaseInsensitive)) return "TEXCOORD2";
      if (programParameter.contains("3", Qt::CaseInsensitive)) return "TEXCOORD3";
      if (programParameter.contains("4", Qt::CaseInsensitive)) return "TEXCOORD4";
      if (programParameter.contains("5", Qt::CaseInsensitive)) return "TEXCOORD5";
      if (programParameter.contains("6", Qt::CaseInsensitive)) return "TEXCOORD6";
      return "TEXCOORD0";
    }
  if (   programParameter.contains("skeleton", Qt::CaseInsensitive)
      && programParameter.contains("bone", Qt::CaseInsensitive))
    {
      return "SKELETON_BONES";
    }
  return "";
}
